#include "Utility/Parsables/IParsable.hpp"

#include <iostream>
#include <list>
#include <map>
#include <string>

namespace Utility
{
	namespace Parsables
	{
		std::list< IParsable * > IParsable::parsablesList;

		IParsable::IParsable( void )
		{
			parsablesList.push_back( this );
		}

		IParsable::~IParsable( void )
		{
		}

		void IParsable::Create( void )
		{
		}

		bool IParsable::HasProperty( const std::string &prop )
		{
			return properties.find( prop ) != properties.end();
		}

		Property IParsable::GetProperty( const std::string &propKey )
		{
			return properties[ propKey ];
		}

		void IParsable::SetProperty( const std::string &propKey, Property &propVal )
		{
			properties[ propKey ] = propVal;
		}

		void IParsable::SetProperty( const std::string &propKey, const std::string &propVal )
		{
			Property prop;
			prop.type = PROPERTY_TYPE_STRING;
			prop.str = propVal;

			SetProperty( propKey, prop );
		}

		void IParsable::SetProperty( const std::string &propKey, IParsable *propVal )
		{
			Property prop;
			prop.type = PROPERTY_TYPE_OBJECT;
			prop.obj = propVal;

			SetProperty( propKey, prop );
		}

		void IParsable::DestroyAll( void )
		{
			std::list< IParsable * >::iterator itr = parsablesList.begin();

			for ( ; itr != parsablesList.end(); itr++ )
			{
				delete *itr;
			}

			parsablesList.clear();
		}
	}
}